package com.lightning.examples.dao;

import java.util.List;

import org.expressme.persist.MappedBy;
import org.expressme.persist.Param;
import org.expressme.persist.Query;
import org.expressme.persist.Unique;
import org.expressme.persist.Update;

import com.lightning.examples.model.Category;
import com.lightning.examples.model.mapper.CategoryRowMapper;
import com.lightning.persist.selectkey.SelectKey;

public interface CategoryDao {
	static final String CATEGORY_ALL = "c.id, c.name, c.code, c.prefix_code, c.state";

	@SelectKey
	@Update("insert into Category (name, code, prefix_code, state) values (:c.name, :c.code, :c.prefixCode, :c.state)")
	int createCategory(@Param("c") Category category);

	@Update("update Category set name=:c.name, code=:c.code, prefix_code=:c.prefixCode, state=:c.state where id=:c.id")
	int updateCategory(@Param("c") Category category);

	@Update("delete from Category where id=:c.id")
	int deleteCategory(@Param("c") Category category);

	@Unique
	@MappedBy(CategoryRowMapper.class)
	@Query("select " + CATEGORY_ALL + " from Category c where id=:id")
	Category queryCategoryById(@Param("id") int id);

	@MappedBy(CategoryRowMapper.class)
	@Query("select " + CATEGORY_ALL + " from Category c where state = '1'")
	List<Category> queryCategorys();
}
